<?php
/**
 * config 参数设置请参考 http://www.ruochigroup.com/main/2008/03/19/bcastr-40/
 */

class SlidePictures extends CWidget {
    public $node_id;
    public $limit = 6;
    public $config = array(
        'autoPlayTime' => 5.5,
        'isShowBtn' => true,
        'isShowTitle' => false,
        'transform' => 'blur',
    );

    public function run() {
        $models = Slide::model()->findRecent($this->node_id, $this->limit);
        $xml = '<data><channel>';
        foreach ($models as $model) {
            $xml .= "<item>
                <link>{$model->url}</link>
                <image>{$model->pictureSource}</image>
                <title>{$model->title}</title>
                </item>";
        }
        $xml .= '</channel>';

        $configs = '';
        foreach ($this->config as $cfg => $value) {
            if (gettype($value) === 'boolean') {
                $v = ($value) ? 'true' : 'false';
            } else {
                $v = $value;
            }
            $configs .= "<{$cfg}>{$v}</{$cfg}>";
        }
        $xml .= "<config>{$configs}</config></data>";
        
        $this->render('SlidePictures', array('xml' => $xml));
    }
}
